<?php

namespace Admin\Controller;

class OtherController extends AdminController {

    public function yonghuxieyi() {
        if (IS_POST) {
            $id = I("id", 0, 'intval');

            $data['desc'] = I("desc");
            $data['update_time'] = date('Y-m-d H:i:s', time());
            $data['key'] = 'yonghuxieyi';

            if ($id == 0) {
                $res = M('Configure')->add($data);
            } else {
                $res = M('Configure')->where(array('id' => $id))->save($data);
            }


            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {
            $data = M('Configure')->where(array("key" => "yonghuxieyi"))->find();

            $this->assign('data', $data);
            $this->assign('meta_title', '用户协议管理');
            $this->display();
        }
    }

    public function kefudianhua() {
        if (IS_POST) {
            $id = I("id", 0, 'intval');

            $data['desc'] = I("desc");
            $data['update_time'] = date('Y-m-d H:i:s', time());
            $data['key'] = 'kefudianhua';

            if ($id == 0) {
                $res = M('Configure')->add($data);
            } else {
                $res = M('Configure')->where(array('id' => $id))->save($data);
            }


            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {    
            $data = M('Configure')->where(array("key" => "kefudianhua"))->find();

            $this->assign('data', $data);
            $this->assign('meta_title', '客服热线设置');
            $this->display();
        }
    }
    public function pintaishoukuan() {
        if (IS_POST) {
            $id = I("id", 0, 'intval');

            $data['desc'] = I("desc");
            $data['update_time'] = date('Y-m-d H:i:s', time());
            $data['key'] = 'pintaishoukuan';

            if ($id == 0) {
                $res = M('Configure')->add($data);
            } else {
                $res = M('Configure')->where(array('id' => $id))->save($data);
            }
            
            //平台账户info
            $pintaishoukuan_info = I('pintaishoukuan_info');
            $ptskData['desc'] = $pintaishoukuan_info;
            
            $ptskInfo = M('Configure')->where(array('key' => 'pintaishoukuan_info'))->find();
            if(empty($ptskInfo)){
                $ptskData['key'] = 'pintaishoukuan_info';
                M('Configure')->add($ptskData);
            }else{
                M('Configure')->where(array('key' => 'pintaishoukuan_info'))->save($ptskData);
            }
            
            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
            
        } else {    
            $data = M('Configure')->where(array("key" => "pintaishoukuan"))->find();
            $data['pintaishoukuan_info'] = M('Configure')->where(array("key" => "pintaishoukuan_info"))->getField('desc');
            $this->assign('data', $data);
            $this->assign('meta_title', '平台收款帐号');
            $this->display();
        }
    }

    public function haitielianyun() {
        if (IS_POST) {
            $id = I("id", 0, 'intval');

            $data['desc'] = I("desc");
            $data['update_time'] = date('Y-m-d H:i:s', time());
            $data['key'] = 'haitielianyun';

            if ($id == 0) {
                $res = M('Configure')->add($data);
            } else {
                $res = M('Configure')->where(array('id' => $id))->save($data);
            }


            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {
            $data = M('Configure')->where(array("key" => "haitielianyun"))->find();

            $this->assign('data', $data);
            $this->assign('meta_title', '海铁联运说明');
            $this->display();
        }
    }
    
    public function jiagemingxi() {
        if (IS_POST) {
            $id = I("id", 0, 'intval');

            $data['desc'] = I("desc");
            $data['update_time'] = date('Y-m-d H:i:s', time());
            $data['key'] = 'jiagemingxi';

            if ($id == 0) {
                $res = M('Configure')->add($data);
            } else {
                $res = M('Configure')->where(array('id' => $id))->save($data);
            }


            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {
            $data = M('Configure')->where(array("key" => "jiagemingxi"))->find();

            $this->assign('data', $data);
            $this->assign('meta_title', '价格明细设置');
            $this->display();
        }
    }

}
